package core.threads;

import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import core.common.Configurations;

public class ThreadPool {

	private static ExecutorService pool = Executors.newFixedThreadPool(
			Configurations.getThreadPoolCount());
	
	public static Future<Void> submitTask(Callable<Void> task) {
		Future<Void> future = pool.submit(task);
		
		pool.submit(new ThreadCallable<Future<Void>, Void>(future) {

			@Override
			public Void call() throws Exception {
				getArgument().get();
				return null;
			}
		});

		return future;
	}
	
	public static void invokeAll(Collection<Callable<Void>> tasks)
			throws InterruptedException {
		pool.invokeAll(tasks);
	}
	
	public static void close() {
		pool.shutdown();
	}
	
	public static void closeNow() {
		pool.shutdownNow();
	}

	
}
